/* 
 * @author Mabel Xu
 * @auther Ryan Cole
 */

import info.gridworld.actor.Actor;
import info.gridworld.actor.Bug;
import info.gridworld.actor.Flower;
import info.gridworld.grid.Grid;
import info.gridworld.grid.Location;

import java.awt.Color;

/**
 * A <code>Jumper</code> jumps across objects in its path. <br />
 */
public class Jumper extends Bug
{
    /**
     * Constructs a Jumper that jumps
     */
    public Jumper()
    {
        super();
    }

    /**
     * Constructs a Jumper with specified color
     * @param bugColor specifies color of bug
     */
    public Jumper(Color bugColor)
    {
    	super(bugColor);
    }

    /**
     * Tests to see if Jumper can move in that direction
     */
    public boolean canMove()
    {
    	Grid<Actor> grid = this.getGrid();
    	if (grid == null)
    		return false;
    	Location next = this.getLocation().getAdjacentLocation(this.getDirection()).getAdjacentLocation(this.getDirection());
    	if (!grid.isValid(next))
    		return false;
    	Actor target = grid.get(next);
    	return (target == null) || (target instanceof Flower);
    }
    
    /**
     * Turns Jumper 90 degrees to the right
     */
    public void turn()
    {
    	this.setDirection(this.getDirection() + Location.RIGHT);
    }
    
    /**
     * Jumps Jumper two spaces forward leaving no flower behind,
     * can land on empty space or Flower
     */
    public void move()
    {
    	Grid<Actor> grid = this.getGrid();
    	if (grid == null)
    		return;
    	Location next = this.getLocation().getAdjacentLocation(this.getDirection()).getAdjacentLocation(this.getDirection());
    	if (grid.isValid(next))
    		this.moveTo(next);
    	else
    		this.removeSelfFromGrid();
    }
}